package stats

import (
	"epg-mc/database/table/config"
	"log"
	"net/http"

	"github.com/labstack/echo"
)

var base *Base

//Base template data
type Base struct {
	data map[string]interface{}
}

func init() {
	base = &Base{data: make(map[string]interface{})}
	base.data["title"] = config.GetValue(config.SiteTitle)
	base.data["uname"] = ""
}

func Server(c echo.Context) error {
	log.Println("server")
	return nil
}

func Service(c echo.Context) error {
	log.Println("service")
	return nil
}

func Grafana(c echo.Context) error {
	base.data["uname"] = c.Get("uname")
	dash := c.Param("dashboard")
	var key string
	switch dash {
	case "system":
		key = config.GrafanaSysMetrics
	case "epgproxy":
		fallthrough
	default:
		key = config.GrafanaEPGProxy
	}
	base.data["data"] = config.FindByKey(key)
	err := c.Render(http.StatusOK, "stats/grafana.html", base.data)
	if err != nil {
		c.Error(err)
	}
	return err
}
